/*
******************************************************************************************
**
**  Copyright (C) 2011, Fujian WITSI Micro-electronic Tech. CO.,LTD., All Rights Reserved.
**
******************************************************************************************
*/
/*
******************************************************************************************
**
**	File: apitrans.h
**
**	Brief:
**
**	Logs:
**		2012.12.26		Created by ttlc
**
******************************************************************************************
*/
#ifndef ___APITRANS_H___
#define ___APITRANS_H___

/*
******************************************************************************************
**	include files 
******************************************************************************************
*/
#include <string.h>

#ifdef __cplusplus
extern "C"{
#endif
/*
******************************************************************************************
**	global referenced macro defines & type defines
******************************************************************************************
*/




#define ASYNC_STAR   1000
//typedef enum {}ERR_CODE;
 
typedef struct{
	uint8_t pan_len;
	uint8_t pan[25];
}pan_t;

#define MAX_SIZE 1024


typedef enum {
	CMD_MIN_NUM = 0x00,
	CMD_LCD_LCR = 0x11,
	CMD_LCD_REVERSE,
	CMD_LCD_BACKLIGHT,
	CMD_LCD_GRAY,
	CMD_LCD_VLINE,
	CMD_LCD_HLINE,
	CMD_LCD_STRING,
	CMD_LCD_IMGER,

	CMD_GET_KEY = 0x21,
	CMD_GET_STRING,

	CMD_MAGC_START = 0X31,
	//CMD_MAGC_END,
	CMD_MAGC_READ,

	CMD_ICC_PRESENT_ = 0x41,
	CMD_ICC_PWRUP_,
	CMD_ICC_APDU_,
	CMD_ICC_PWRDOWN_,
	
	CMD_PRN_INIT = 0x91,
	CMD_PRN_GETSTATUS,
	CDM_INIT_FONT,
	CMD_PRN_HEATTIME,
	CMD_PRN_STRING,
	CMD_PRN_EXIT,

	CMD_SHA1 = 0x61,
	CMD_SHA2,
	CMD_DES_KEY,
	CMD_DES,
	CMD_DES3_KEY,
	CMD_DES3,

	CMD_GET_STATUS = 0X71,
	CMD_NV_READ,
	CMD_NV_WRITE,
	
	CMD_FILE_OPEN = 0X81,
	CMD_FILE_CLOSE,
	CMD_FILE_READ,
	CMD_FILE_WRITE,
	CMD_FILE_LSEEK,
	CMD_FILE_ULINK,

	CMD_BUZZER_CTL = 0xb1,
	CMD_LED_CTL, 
	CMD_SET_TIME,
	CMD_GET_TIME,
	CMD_TIME_DELAY,
	CMD_ALL = 0xFF,
	ERR_SAFE_SYSTEM = 0x8300,
}api_cmd_t;


#define S		1000
#define TIMEOUT_S	30



#define SAFE_ERR_CODE( err_code) (1000 - (4000 + err_code))
#define FILE_ERR_CODE( err_code) (-err_code)

/*
** RETURN:
**	>0: package length, package in the cmd buffer
**	=0: ok and nothing to respone
**	<0: error code while excusive cmd
typedef int fn_cmd_api_t(unsigned char *cmd, int len);
*/

typedef void (*apitrans_t)(void);
#define __apitrans_entry	__attribute__((__used__, section(".apitrans")))
#define apitrans_initcall(fn)    \
        static const apitrans_t _apitrans_initcall_##fn \
        __attribute__((__used__, section(".apitrans"))) = fn

typedef int (*func_t)(unsigned char* in, int inlen);

//#define AUX_BT 0


int put_string(char *buf,int len);

int get_1(int timeout);

int get_string(char *buf,int len,int timeout);

int put_string(char *buf,int len);

int DectoBCD(int Dec, unsigned char *Bcd, int length);

unsigned long  BCDtoDec(const unsigned char *bcd, int length);

int  debug_aux( const char *format, ... );

int  debug_aux_hex( char *title,uint8_t * data, int dataLen );

int timeouts_test( uint32_t timeout  );

void timeouts_start( uint32_t start_time );

int get_currtime();

int timeouts_cmp(uint32_t currtime,uint32_t timeout);

int rdp_send_recv_cmd(uint8_t *cmd, int inlen, uint8_t * in, uint8_t * out, int timeout);

int rdp_recv_send_cmd(uint8_t *cmd, uint8_t * out);

int rdp_recv_requset_cmd(uint8_t *cmd, uint8_t * out);

void rdp_send_respond_cmd(uint8_t *cmd,int respond, int datalen, uint8_t *data);


/*
**========================================================================================
**	End of this file.
**	Don't insert any data after this block.
**========================================================================================
*/
#ifdef __cplusplus
}
#endif

#endif	//___APITRANS_H___

